package gewu.suleju.controller;

import gewu.suleju.model.vo.HouseInforAll;
import gewu.suleju.model.vo.Result;
import gewu.suleju.sevice.IHouseInforAllService;
import gewu.suleju.sevice.ISearchHouseInforOneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("houseInfor")
public class HouseInforController {
    @Autowired
    private IHouseInforAllService houseInforAllService;

    @Autowired
    private ISearchHouseInforOneService searchHouseInforOneService;

    @ResponseBody//将java对象转化成json对象
    @PostMapping("hot")
    public Result HouseInforHot(){
        List<HouseInforAll> houseInforAllList = houseInforAllService.findForHouseInforAll();

        if(houseInforAllList!=null && houseInforAllList.size()!=0){
            return new Result("200","全部数据",houseInforAllList);
        }
        return new Result("500","无数据");
    }

    @ResponseBody//将java对象转化成json对象
    @PostMapping("rent")
    public Result HouseInforRent(String rentType){
        List<HouseInforAll> houseInforAllList = searchHouseInforOneService.findByRentType(rentType.trim());

        if(houseInforAllList!=null && houseInforAllList.size()!=0){
            return new Result("200","全部数据",houseInforAllList);
        }
        return new Result("500","无数据");
    }

    @ResponseBody//将java对象转化成json对象
    @PostMapping("region")
    public Result HouseInforRegion(String area){
        List<HouseInforAll> houseInforAllList = searchHouseInforOneService.findByArea(area.trim());

        if(houseInforAllList!=null && houseInforAllList.size()!=0){
            return new Result("200","全部数据",houseInforAllList);
        }
        return new Result("500","无数据");
    }

    @ResponseBody//将java对象转化成json对象
    @PostMapping("subway")
    public Result HouseInforSubway(String subway){
        List<HouseInforAll> houseInforAllList = searchHouseInforOneService.findBySubway(subway.trim());

        if(houseInforAllList!=null && houseInforAllList.size()!=0){
            return new Result("200","全部数据",houseInforAllList);
        }
        return new Result("500","无数据");
    }
}
